package com.itkaien.anno;

import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component
@Scope("singleton")
@Lazy(value = false)
public class UserService {

    private String name = "itkaien";


//    @Resource
//    private PersonInterface person1;
//
//    @Resource
//    private PersonInterface person;
//
//    @Resource(name = "person1")
//    private PersonInterface personss;

    @Autowired
    private PersonInterface person1;

    @Autowired
    private PersonInterface person;

    @Autowired
    @Qualifier("person1")
    private PersonInterface personss;

    @Value("${JDBC.username}")
    private String username;
    public void add() {
        System.out.println("add...");
    }
    @PostConstruct
    public void init(){
        System.out.println("init...");
    }

    @PreDestroy
    public void destroy(){
        System.out.println("destroy..."+username);
        person1.eat();
        person.eat();
        personss.eat();
        System.out.println("destroy...");
    }
}
